package com.tuosha.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.irs.util.ResultUtil;
import com.tuosha.dao.CategoriesDao;
import com.tuosha.model.CategoriesEntity;
import com.tuosha.model.PostsListEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Map;

import com.tuosha.dao.PostsDao;
import com.tuosha.model.PostsEntity;
import com.tuosha.service.PostsService;



@Service("postsServiceImpl")
public class PostsServiceImpl implements PostsService {
	@Autowired
	private PostsDao postsDao;

	@Autowired
	private CategoriesDao categoriesDao;

	@Override
	public PostsEntity queryObject(Integer id){
		return postsDao.queryObject(id);
	}
	
	@Override
	public List<PostsEntity> queryList(Map<String, Object> map){
		return postsDao.queryList(map);
	}
	
	@Override
	public int queryTotal(Map<String, Object> map){
		return postsDao.queryTotal(map);
	}

	@Override
	public int delete(Integer id){
		return postsDao.delete(id);
	}

	@Override
	public int deleteBatch(Integer[] ids){
		return postsDao.deleteBatch(ids);
	}

	@Override
	public void save(PostsEntity hkjs){
		Date date=new Date();
		hkjs.setCreatedAt(date);
		postsDao.save(hkjs);
	}

	@Override
	public int update(PostsEntity hkjs){
		Date date=new Date();
		hkjs.setUpdatedAt(date);
		return postsDao.update(hkjs);
	}

	public int delById(Integer id){
		Date date=new Date();
		PostsEntity ties= new PostsEntity();
		ties.setId(id);
		ties.setDeletedAt(date);
		return postsDao.update(ties);
	}

	public int delPatch(String  tiestr){
		String[] strs = tiestr.split(",");
		if(strs!=null&&strs.length>0){
			for (String str : strs) {
				delById(Integer.parseInt(str));
			}
		}
		return 0;
	}

	public PostsEntity queryName(String name){
		return postsDao.queryName(name);
	}

	@Override
	public List<PostsListEntity> queryListItem(Map<String, Object> map){

		return postsDao.queryListItem(map);
	}

	@Override
	public List<CategoriesEntity> queryListName() {

		List<CategoriesEntity> list = categoriesDao.queryListName();

		return list;
	}
}
